<template>
  <div class="settings">
    <van-nav-bar safe-area-inset-top placeholder :title="$t('AdvancedSetting')" left-arrow fixed @click-left="onClickLeft" />
    <van-pull-refresh v-model="isLoading" :pulling-text="$t('PullingText')" :loosing-text="$t('PullingText')" :success-text="$t('refreshSuccee')" @refresh="onRefresh">
      <van-collapse class="marginTop15" v-model="activeNames">
        <van-collapse-item :title="$t('Safety')" name="1">
          <safetyPTVue :deviceType="10" :safety="safety" :reg="9" :key="timer" @getFormData="setSafety"></safetyPTVue>
        </van-collapse-item>
        <van-collapse-item title="L/HVRT" name="2" v-if="safety==1||safety==2||safety==3">
          <div class="pltxt">FuncLV Slect</div>
          <van-field v-model="LocalArr.FuncLV" clickable readonly @click="showFuncLV = true">
            <template #button>
              <van-button size="small" round @click="GridSupport($event)" class="setbtn">{{$t('Save')}}</van-button>
            </template>
          </van-field>
          <van-popup v-model="showFuncLV" round position="bottom">
            <van-picker show-toolbar :columns="toggleArr" 
              @cancel="showFuncLV = false" 
              @confirm="FuncLVConfirm"
              :confirm-button-text="$t('OK')"
              :cancel-button-text="$t('Cancel')" 
            />
          </van-popup>
          <div class="pltxt">FuncHV Slect</div>
          <van-field v-model="LocalArr.FuncHV" clickable readonly @click="showFuncHV = true">
            <template #button>
              <van-button size="small" round @click="GridSupport($event)" class="setbtn">{{$t('Save')}}</van-button>
            </template>
          </van-field>
          <van-popup v-model="showFuncHV" round position="bottom">
            <van-picker show-toolbar :columns="toggleArr" 
              @cancel="showFuncHV = false" 
              @confirm="FuncHVConfirm" 
              :confirm-button-text="$t('OK')"
              :cancel-button-text="$t('Cancel')"
            />
          </van-popup>
          <pfLockInPointPTVue :setName="$t('HV2')" :setUntil="'%'" :setMin="101" :setMax="120" :setValue.sync="LocalArr.VacMaxValue" :reg="6"></pfLockInPointPTVue>
          <tripFreVue :setName="'Trip Time HV2'" :setUntil="'Ms'" :setValue="160"></tripFreVue>
          <pfLockInPointPTVue :setName="$t('HV1')" :setUntil="'%'" :setMin="101" :setMax="120" :setValue.sync="LocalArr.VacMaxSlowProtectValue" :reg="13"></pfLockInPointPTVue>
          <vacMaxPTVue :setName="'Trip Time HV1'" :setUntil="'S'" :setMin="'1.0'" :setMax="'60.0'" :setValue.sync="LocalArr.TripTimeHV1Value" :reg="78"></vacMaxPTVue>
          <pfLockInPointPTVue :setName="$t('LV1')" :setUntil="'%'" :setMin="45" :setMax="99" :setValue.sync="LocalArr.VacMinSlowProtectValue" :reg="12"></pfLockInPointPTVue>
          <vacMaxPTVue :setName="'Trip Time LV1'" :setUntil="'S'" :setMin="'1.0'" :setMax="'60.0'" :setValue.sync="LocalArr.TripTimeLV1Value" :reg="77"></vacMaxPTVue>
          <pfLockInPointPTVue :setName="$t('LV2')" :setUntil="'%'" :setMin="45" :setMax="99" :setValue.sync="LocalArr.LV2Value" :reg="150"></pfLockInPointPTVue>
          <vacMaxPTVue :setName="$t('TripTimeLV2')" :setUntil="'S'" :setMin="'1.0'" :setMax="'60.0'" :setValue.sync="LocalArr.TripTimeLV2Value" :reg="151"></vacMaxPTVue>
          <pfLockInPointPTVue :setName="$t('LV3')" :setUntil="'%'" :setMin="45" :setMax="99" :setValue.sync="LocalArr.VacMinValue" :reg="5"></pfLockInPointPTVue>
          <vacMaxPTVue :setName="'Trip Time LV3'" :setUntil="'S'" :setMin="0.5" :setMax="'60.0'" :setValue.sync="LocalArr.TripTimeLV3Value" :reg="73" v-if="safety==1"></vacMaxPTVue>
          <vacMaxPTVue :setName="'Trip Time LV3'" :setUntil="'S'" :setMin="'1.0'" :setMax="'60.0'" :setValue.sync="LocalArr.TripTimeLV3Value" :reg="73" v-if="safety==2"></vacMaxPTVue>
        </van-collapse-item>
        <van-collapse-item title="L/HFRT" name="3" v-if="safety==1||safety==2||safety==3">
          <div class="pltxt">FuncLF Slect</div>
          <van-field v-model="LocalArr.FuncLF" clickable readonly @click="showFuncLF = true">
            <template #button>
              <van-button size="small" round @click="GridSupport($event)" class="setbtn">{{$t('Save')}}</van-button>
            </template>
          </van-field>
          <van-popup v-model="showFuncLF" round position="bottom">
            <van-picker show-toolbar :columns="toggleArr" 
              @cancel="showFuncLF = false" 
              @confirm="FuncLFConfirm" 
              :confirm-button-text="$t('OK')"
              :cancel-button-text="$t('Cancel')" 
            />
          </van-popup>
          <div class="pltxt">FuncHF Slect</div>
          <van-field v-model="LocalArr.FuncHF" clickable readonly @click="showFuncHF = true">
            <template #button>
              <van-button size="small" round @click="GridSupport($event)" class="setbtn">{{$t('Save')}}</van-button>
            </template>
          </van-field>
          <van-popup v-model="showFuncHF" round position="bottom">
            <van-picker show-toolbar :columns="toggleArr" 
              @cancel="showFuncHF = false" 
              @confirm="FuncHFConfirm"
              :confirm-button-text="$t('OK')"
              :cancel-button-text="$t('Cancel')"  
            />
          </van-popup>
          <facMaxPTVue :setName="$t('HF2')" :setUntil="'Hz'" :setMin="'60.10'" :setMax="'66.00'" :setValue.sync="LocalArr.FacMaxValue" :reg="8"></facMaxPTVue>
          <tripTimeHF :setName="'Trip Time HF2'" :setUntil="'S'" :setMin="0.16" :setMax="'1000.00'" :setValue.sync="LocalArr.TripTimeHF2Value" :reg="76" :division="0.02"></tripTimeHF>
          <facMaxPTVue :setName="$t('HF1')" :setUntil="'Hz'" :setMin="'60.10'" :setMax="'66.00'" :setValue.sync="LocalArr.FacMaxSlowProtectValue" :reg="15"></facMaxPTVue>
          <tripTimeHF :setName="'Trip Time HF1'" :setUntil="'S'" :setMin="'1.00'" :setMax="'1000.00'" :setValue.sync="LocalArr.TripTimeHF1Value" :reg="80" :division="0.02"></tripTimeHF>
          <facMaxPTVue :setName="$t('LF1')" :setUntil="'Hz'" :setMin="'53.00'" :setMax="'59.90'" :setValue.sync="LocalArr.FacMinSlowProtectValue" :reg="14"></facMaxPTVue>
          <tripTimeHF :setName="'Trip Time LF1'" :setUntil="'S'" :setMin="'1.00'" :setMax="'1000.00'" :setValue.sync="LocalArr.TripTimeLF1Value" :reg="79" :division="0.02"></tripTimeHF>
          <facMaxPTVue :setName="$t('LF2')" :setUntil="'Hz'" :setMin="'53.00'" :setMax="'59.90'" :setValue.sync="LocalArr.FacMinValue" :reg="7"></facMaxPTVue>
          <tripTimeHF :setName="'Trip Time LF2'" :setUntil="'S'" :setMin="0.16" :setMax="'1000.00'" :setValue.sync="LocalArr.TripTimeLF2Value" :reg="75" :division="0.02"></tripTimeHF>
        </van-collapse-item>
        <van-collapse-item title="RR" name="4" v-if="safety==1||safety==2">
          <div class="pltxt">{{$t('FuncSelect')}}</div>
          <van-field v-model="LocalArr.FuncRR" clickable readonly @click="showFuncRR = true">
            <template #button>
              <van-button size="small" round @click="GridSupport($event)" class="setbtn">{{$t('Save')}}</van-button>
            </template>
          </van-field>
          <van-popup v-model="showFuncRR" round position="bottom">
            <van-picker show-toolbar :columns="toggleArr" 
              @cancel="showFuncRR = false" 
              @confirm="FuncRRConfirm"
              :confirm-button-text="$t('OK')"
              :cancel-button-text="$t('Cancel')" 
            />
          </van-popup>
          <facMaxPTVue :setName="$t('NormRampRate')" :setUntil="'%'" :setMin="'1.00'" :setMax="'100.00'" :setValue.sync="LocalArr.NormRampRateValue" :reg="156"></facMaxPTVue>
          <facMaxPTVue :setName="$t('SoftRampUpRate')" :setUntil="'%'" :setMin="'2.00'" :setMax="'100.00'" :setValue.sync="LocalArr.SoftRampUpRateValue" :reg="157" v-if="safety==1"></facMaxPTVue>
          <facMaxPTVue :setName="$t('SoftRampUpRate')" :setUntil="'%'" :setMin="'0.10'" :setMax="'100.00'" :setValue.sync="LocalArr.SoftRampUpRateValue" :reg="157" v-if="safety==2"></facMaxPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('PowerFactor')" name="5" v-if="safety==1||safety==2">
          <div class="pltxt">{{$t('FuncSelect')}}</div>
          <van-field v-model="LocalArr.FuncPF" clickable readonly @click="showFuncPF = true">
            <template #button>
              <van-button size="small" round @click="GridSupport($event)" class="setbtn">{{$t('Save')}}</van-button>
            </template>
          </van-field>
          <van-popup v-model="showFuncPF" round position="bottom">
            <van-picker show-toolbar :columns="GridSupportsArr" 
              @cancel="showFuncPF = false" 
              @confirm="FuncPFConfirm"
              :confirm-button-text="$t('OK')"
              :cancel-button-text="$t('Cancel')" 
            />
          </van-popup>
          <van-form @submit="powerfactorSubmit" v-if="isSPF">
            <van-field :value="LocalArr.factMode" :label="$t('ModeSelect')" readonly clickable name="picker" input-align="right" @click="showPowerFact = true" />
            <van-popup v-model="showPowerFact" round position="bottom">
              <van-picker show-toolbar :columns="factorArr" 
                @cancel="showPowerFact = false" 
                @confirm="factModeConfirm"
                :confirm-button-text="$t('OK')"
                :cancel-button-text="$t('Cancel')" 
              />
            </van-popup>
            <van-field 
              v-model="LocalArr.P2Value" 
              :label="$t('PFValue')" 
              type="number" 
              show-error 
              name="validator" 
              input-align="right" 
              error-message-align="right" 
              clearable 
              :rules="[{ validator:P2validator,message: `${$t('Range')}：80-100` }]" 
            />
            <div class="factorBtnBox">
              <van-button block round>{{$t('Save')}}</van-button>
            </div>
          </van-form>
          <vacMaxPTVue :setName="'Q1'" :setUntil="'%'" :setMin="'0.0'" :setMax="'100.0'" :setValue.sync="LocalArr.Q1Value" :reg="97"></vacMaxPTVue>
          <vacMaxPT2Vue :setName="'Q2'" :setUntil="'%'" :setMin="'-100.0'" :setMax="'100.0'" :setValue.sync="LocalArr.Q2Value" :reg="98"></vacMaxPT2Vue>
          <vacMaxPT2Vue :setName="'Q3'" :setUntil="'%'" :setMin="'-100.0'" :setMax="'100.0'" :setValue.sync="LocalArr.Q3Value" :reg="99"></vacMaxPT2Vue>
          <vacMaxPT2Vue :setName="'Q4'" :setUntil="'%'" :setMin="'-100.0'" :setMax="'0.0'" :setValue.sync="LocalArr.Q4Value" :reg="100"></vacMaxPT2Vue>
          <vacMaxPTVue :setName="'Vref'" :setUntil="'%'" :setMin="'95.0'" :setMax="'105.0'" :setValue.sync="LocalArr.VrefValue" :reg="101"></vacMaxPTVue>
          <vacMaxPTVue :setName="'ResponseTime'" :setUntil="'S'" :setMin="'1.0'" :setMax="'90.0'" :setValue.sync="LocalArr.ResponseTimeValue" :reg="102"></vacMaxPTVue>
          <vacMaxPTVue :setName="'V1'" :setUntil="'%'" :setMin="'82.0'" :setMax="'118.0'" :setValue.sync="LocalArr.V1Value" :reg="103"></vacMaxPTVue>
          <vacMaxPTVue :setName="'V2'" :setUntil="'%'" :setMin="'82.0'" :setMax="'118.0'" :setValue.sync="LocalArr.V2Value" :reg="104"></vacMaxPTVue>
          <vacMaxPTVue :setName="'V3'" :setUntil="'%'" :setMin="'82.0'" :setMax="'118.0'" :setValue.sync="LocalArr.V3Value" :reg="105"></vacMaxPTVue>
          <vacMaxPTVue :setName="'V4'" :setUntil="'%'" :setMin="'82.0'" :setMax="'118.0'" :setValue.sync="LocalArr.V4Value" :reg="106"></vacMaxPTVue>
        </van-collapse-item>
        <van-collapse-item title="Frequency-Watt Mode" name="6" v-if="safety!=3">
          <div class="pltxt">{{$t('FuncSelect')}}</div>
          <van-field v-model="LocalArr.FuncFW" clickable readonly @click="showFuncFW = true">
            <template #button>
              <van-button size="small" round @click="GridSupport($event)" class="setbtn">{{$t('Save')}}</van-button>
            </template>
          </van-field>
          <van-popup v-model="showFuncFW" round position="bottom">
            <van-picker show-toolbar :columns="toggleArr" 
              @cancel="showFuncFW = false" 
              @confirm="FuncFWConfirm"
              :confirm-button-text="$t('OK')"
              :cancel-button-text="$t('Cancel')" 
            />
          </van-popup>
          <van-form @submit="startPointSubmit" v-if="safety==1">
            <van-field :value="LocalArr.startPointV1" label="FreqHighPoint (Hz)" readonly clickable name="picker" input-align="right" @click="showStartPointV1 = true" />
            <van-popup v-model="showStartPointV1" round position="bottom">
              <van-picker show-toolbar :columns="StartPointV1Arr" 
                @cancel="showStartPointV1 = false" 
                @confirm="StartPointV1Confirm"
                :confirm-button-text="$t('OK')"
                :cancel-button-text="$t('Cancel')" 
              />
            </van-popup>
            <van-field :value="LocalArr.startPointV2" label="FreqLowPoint (Hz)" readonly clickable name="picker" input-align="right" @click="showStartPointV2 = true" />
            <van-popup v-model="showStartPointV2" round position="bottom">
              <van-picker show-toolbar :columns="StartPointV2Arr" 
                @cancel="showStartPointV2 = false" 
                @confirm="StartPointV2Confirm"
                :confirm-button-text="$t('OK')"
                :cancel-button-text="$t('Cancel')" 
              />
            </van-popup>
            <div class="factorBtnBox">
              <van-button block round>{{$t('Save')}}</van-button>
            </div>
          </van-form>
          <tripFreVue :setName="$t('SlopeOfFreqDroop')" :setUntil="'%/Hz'" :setValue="50" v-if="safety==1"></tripFreVue>
          <dbofVue :setName="'dbOF'" :setUntil="'Hz'" :setMin="0.017" :setMax="'1.000'" :setValue.sync="LocalArr.dbOFValue" :reg="107" v-if="safety==2"></dbofVue>
          <dbofVue :setName="'dbUF'" :setUntil="'Hz'" :setMin="0.017" :setMax="'1.000'" :setValue.sync="LocalArr.dbUFValue" :reg="108" v-if="safety==2"></dbofVue>
          <facMaxPTVue :setName="'KOF'" :setMin="0.02" :setMax="0.07" :setValue.sync="LocalArr.KOFValue" :reg="109" v-if="safety==2"></facMaxPTVue>
          <facMaxPTVue :setName="'KUF'" :setMin="0.02" :setMax="0.07" :setValue.sync="LocalArr.KUFValue" :reg="110" v-if="safety==2"></facMaxPTVue>
          <vacMaxPTVue :setName="'FWResponseTimer'" :setUntil="'S'" :setMin="0.5" :setMax="'5.0'" :setValue.sync="LocalArr.FWResponseTimerValue" :reg="111" v-if="safety==2"></vacMaxPTVue>
        </van-collapse-item>
        <van-collapse-item title="Volt-Watt Mode" name="7" v-if="safety==1||safety==2">
          <div v-if="safety==1||safety==2">
            <div class="pltxt">{{$t('FuncSelect')}}</div>
            <van-field v-model="LocalArr.FuncVW" clickable readonly @click="showFuncVW = true">
              <template #button>
                <van-button size="small" round @click="GridSupport($event)" class="setbtn">{{$t('Save')}}</van-button>
              </template>
            </van-field>
            <van-popup v-model="showFuncVW" round position="bottom">
              <van-picker show-toolbar :columns="toggleArr" 
                @cancel="showFuncVW = false" 
                @confirm="FuncVWConfirm"
                :confirm-button-text="$t('OK')"
                :cancel-button-text="$t('Cancel')" 
              />
            </van-popup>
            <vacMaxPTVue :setName="'V2'" :setUntil="'%'" :setMin="'105.0'" :setMax="'109.0'" :setValue.sync="LocalArr.SetV3Value" :reg="119"></vacMaxPTVue>
            <vacMaxPTVue :setName="'V3'" :setUntil="'%'" :setMin="'106.0'" :setMax="'111.0'" :setValue.sync="LocalArr.SetV4Value" :reg="120"></vacMaxPTVue>
          </div>
          <vacMaxPTVue :setName="$t('SlopeOfApwrRed')" :setUntil="'%'" :setMin="'20.0'" :setMax="'50.0'" :setValue.sync="LocalArr.SlopeOfApwrRedValue" :reg="155" v-if="safety==1||safety==2"></vacMaxPTVue>
          <vacMaxPTVue :setName="'VwResponseTimer'" :setUntil="'S'" :setMin="0.5" :setMax="'60.0'" :setValue.sync="LocalArr.VwResponseTimerValue" :reg="112" v-if="safety==2"></vacMaxPTVue>
          <tripFreVue :setName="'W2'" :setUntil="'%'" :setValue="100" v-if="safety==1||safety==2"></tripFreVue>
          <tripFreVue :setName="'W3'" :setUntil="'%'" :setValue="0" v-if="safety==1||safety==2"></tripFreVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Charger')" name="8">
          <pfLockInPointPTVue :setName="$t('MinCapacity')" :setUntil="'%'" :setMin="10" :setMax="100" :setValue.sync="LocalArr.MinCapacityValue" :reg="32" v-if="isLeadAcid"></pfLockInPointPTVue>
          <vacMaxPTVue :setName="$t('ChargeMaxCurrent')" :setUntil="'A'" :setMin="'0.0'" :setMax="'25.0'" :setValue.sync="LocalArr.ChargeMaxCurrentValue" :reg="36"></vacMaxPTVue>
          <vacMaxPTVue :setName="$t('DischargeMaxCurrent')" :setUntil="'A'" :setMin="'0.0'" :setMax="'25.0'" :setValue.sync="LocalArr.DischargeMaxCurrentValue" :reg="37"></vacMaxPTVue>
          <languagePTVue :setName="$t('LowSocChgFromGrid')" :columns="toggleArr" :setValue="LocalArr.LowSocChgFromGridValue" :reg="180"></languagePTVue>
          <languagePTVue :setName="$t('BatteryAwaken')" :columns="toggleArr" :setValue="LocalArr.BatAwakenValue" :reg="86"></languagePTVue>
          <van-divider>Grid-Tied Min SOC</van-divider>
          <languagePTVue :setName="$t('FuncSelect')" :columns="toggleArr" :setValue="LocalArr.NormalMidSocENCode" :reg="181"></languagePTVue>
          <pfLockInPointPTVue :setName="$t('MinCapacity')" :setUntil="'%'" :setMin="10" :setMax="100" :setValue.sync="LocalArr.wMidSocValue" :reg="182"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('ExportControl')" name="9">
          <pfLockInPointPTVue :setName="$t('UserValue')" :setUntil="'W'" :setMin="0" :setMax="60000" :setValue.sync="LocalArr.ExportLimitValue" :reg="66"></pfLockInPointPTVue>
        </van-collapse-item>
        <van-collapse-item title="GlblMPPT Function" name="10">
          <languagePTVue :columns="toggleArr" :setValue="LocalArr.GlblMPPTFunctionCode" :reg="132"></languagePTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('Reset')" name="11">
          <resetINVEnergyPTVue :setName="$t('ClearInverterHistory')" :reg="30"></resetINVEnergyPTVue>
          <resetINVEnergyPTVue :setName="$t('ResetErrorLogs')" :reg="144"></resetINVEnergyPTVue>
          <resetINVEnergyPTVue :setName="$t('ResetMeter1Energy')" :reg="134"></resetINVEnergyPTVue>
        </van-collapse-item>
        <van-collapse-item :title="$t('GridConfigurationSelect')" name="12">
          <van-field v-model="LocalArr.GridConfigurationSelect" clickable readonly @click="showGridCs = true">
          <template #button>
            <van-button size="small" round @click="setGridCs($event)" class="setbtn">{{$t('Save')}}</van-button>
          </template>
          </van-field>
          <van-popup v-model="showGridCs" round position="bottom">
            <van-picker show-toolbar :columns="GridCsArr" 
              @cancel="showGridCs = false" 
              @confirm="GridCsConfirm"
              :confirm-button-text="$t('OK')"
              :cancel-button-text="$t('Cancel')" 
            />
          </van-popup>
        </van-collapse-item>
        <van-collapse-item title="ReConnection Set" name="13">
          <div v-if="safety!=2">
            <van-field v-model="LocalArr.ReConnectionTime" clickable readonly @click="showReConnect = true">
            <template #button>
              <van-button size="small" round @click="setReConnect($event)" class="setbtn">{{$t('Save')}}</van-button>
            </template>
            </van-field>
            <van-popup v-model="showReConnect" round position="bottom">
              <van-datetime-picker v-model="LocalArr.ReConnectionTime" type="time" :min-hour="1" :max-hour="5"
                @cancel="showReConnect = false"
                @confirm="ReConnectConfirm"
                :confirm-button-text="$t('OK')"
                :cancel-button-text="$t('Cancel')"
                @change="fiveChange"
                :max-minute="maxM"
              />
            </van-popup>
          </div>
          <div v-if="safety==2">
            <van-field v-model="LocalArr.ReConnectionTime" clickable readonly @click="showReConnect2 = true">
            <template #button>
              <van-button size="small" round @click="setReConnect($event)" class="setbtn">{{$t('Save')}}</van-button>
            </template>
            </van-field>
            <van-popup v-model="showReConnect2" round position="bottom">
              <van-datetime-picker v-model="LocalArr.ReConnectionTime" type="time" :min-hour="1" :max-hour="10"
                @cancel="showReConnect2 = false"
                @confirm="ReConnectConfirm2"
                :confirm-button-text="$t('OK')"
                :cancel-button-text="$t('Cancel')"
                @change="tenChange"
                :max-minute="maxM2"
              />
            </van-popup>
            <pfLockInPointPTVue :setName="'MaxVolt'" :setUntil="'%'" :setMin="101" :setMax="110" :setValue.sync="LocalArr.MaxVoltValue" :reg="113"></pfLockInPointPTVue>
            <pfLockInPointPTVue :setName="'MinVolt'" :setUntil="'%'" :setMin="88" :setMax="99" :setValue.sync="LocalArr.MinVoltValue" :reg="114"></pfLockInPointPTVue>
            <vacMaxPTVue :setName="'MaxFreq'" :setUntil="'Hz'" :setMin="60.1" :setMax="'61.0'" :setValue.sync="LocalArr.MaxFreqValue" :reg="115"></vacMaxPTVue>
            <vacMaxPTVue :setName="'MinFreq'" :setUntil="'Hz'" :setMin="'59.0'" :setMax="59.9" :setValue.sync="LocalArr.MinFreqValue" :reg="116"></vacMaxPTVue>
          </div>
        </van-collapse-item>
        <van-collapse-item :title="$t('NewPassword')" name="14">
          <newPasswordPTVue :setValue.sync="LocalArr.NewPasswordValue" :reg="88"></newPasswordPTVue>
        </van-collapse-item>
        <van-collapse-item :title="'Micro Grid'" name="15">
          <facMaxPTVue :setName="'Start Freq'" :setUntil="'Hz'" :setMin="'60.00'" :setMax="'66.00'" :setValue.sync="LocalArr.StartFreqValue" :reg="161"></facMaxPTVue>
          <pfLockInPointPTVue :setName="'InvMaxPow'" :setUntil="'W'" :setMin="0" :setMax="10000" :setValue.sync="LocalArr.InvMaxPowValue" :reg="162"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="'Freq Droop'" :setUntil="'%'" :setMin="0" :setMax="100" :setValue.sync="LocalArr.FreqDroopValue" :reg="163"></pfLockInPointPTVue>
          <pfLockInPointPTVue :setName="'FreqReverBatCap'" :setUntil="'%'" :setMin="30" :setMax="80" :setValue.sync="LocalArr.FreqReverBatCapValue" :reg="164"></pfLockInPointPTVue>
        </van-collapse-item>
      </van-collapse>
    </van-pull-refresh>
  </div>
</template>

<script>
import safetyPTVue from '../../../components/Safety/BDSafetyPT'
import pfLockInPointPTVue from '../../../components/PfLockInPoint/BDPfLockInPointPT'
import tripFreVue from '../../../components/TripFre/TripFre'
import vacMaxPTVue from '../../../components/VacMax/BDVacMaxPT'
import facMaxPTVue from '../../../components/FacMax/BDFacMaxPT'
import dbofVue from '../../../components/Dbof/BDDbof'
import languagePTVue from '../../../components/Language/BDLanguagePT'
import resetINVEnergyPTVue from '../../../components/ResetINVEnergy/BDResetINVEnergyPT'
import newPasswordPTVue from '../../../components/NewPassword/BDNewPasswordPT'
import tripTimeHF from '../../../components/TripTimeHF/BDTripTimeHF'
import vacMaxPT2Vue from '../../../components/VacMax/BDVacMax2PT'

export default {
  components:{
    safetyPTVue,
    pfLockInPointPTVue,
    tripFreVue,
    vacMaxPTVue,
    facMaxPTVue,
    dbofVue,
    languagePTVue,
    resetINVEnergyPTVue,
    newPasswordPTVue,
    tripTimeHF,
    vacMaxPT2Vue
  },
  data(){
    return {
      isLoading:false,
      timer:'',
      activeNames:[],
      safety:sessionStorage.getItem('safety'),
      toggleArr:[this.$t('Disable'),this.$t('Enable')],
      isSPF:false,
      isQV:false,
      showFuncLV:false,
      FuncLVCode:'',
      showFuncHV:false,
      FuncHVCode:'',
      showFuncLF:false,
      FuncLFCode:'',
      showFuncHF:false,
      FuncHFCode:'',
      showFuncRR:false,
      FuncRRCode:'',
      GridSupportsArr:[this.$t('Off'),this.$t('Q(u)'),'SPF'],
      showFuncPF:false,
      FuncPFCode:'',
      showPowerFact:false,
      factorArr:[{text:'ind',code:1},{text:'cap',code:2}],
      factModeCode:'',
      showFuncFW:false,
      FuncFWCode:'',
      StartPointV1Arr:['60.10','60.04'],
      showStartPointV1:false,
      StartPointV2Arr:['59.90','59.96'],
      showStartPointV2:false,
      showFuncVW:false,
      FuncVWCode:'',
      isLeadAcid:false,
      showGridCs:false,
      GridCsArr:['240V'],
      GridConfigurationSelectCode:'',
      showReConnect:false,
      showReConnect2:false,
      maxM:59,
      maxM2:59,
      LocalArr:{
        LowSocChgFromGridValue:'',
        BatAwakenValue:'',
        GlblMPPTFunctionCode:'',
        FuncLV:'',
        FuncHV:'',
        VacMaxValue:'',
        VacMaxSlowProtectValue:'',
        TripTimeHV1Value:'',
        VacMinSlowProtectValue:'',
        TripTimeLV1Value:'',
        LV2Value:'',
        TripTimeLV2Value:'',
        VacMinValue:'',
        TripTimeLV3Value:'',
        FuncLF:'',
        FuncHF:'',
        FacMaxValue:'',
        TripTimeHF2Value:'',
        FacMaxSlowProtectValue:'',
        TripTimeHF1Value:'',
        FacMinSlowProtectValue:'',
        TripTimeLF1Value:'',
        FacMinValue:'',
        TripTimeLF2Value:'',
        FuncRR:'',
        NormRampRateValue:'',
        SoftRampUpRateValue:'',
        FuncPF:'',
        factMode:'',
        P2Value:'',
        Q1Value:'',
        Q2Value:'',
        Q3Value:'',
        Q4Value:'',
        VrefValue:'',
        ResponseTimeValue:'',
        V1Value:'',
        V2Value:'',
        V3Value:'',
        V4Value:'',
        FuncFW:'',
        startPointV1:'',
        startPointV2:'',
        dbOFValue:'',
        dbUFValue:'',
        KOFValue:'',
        KUFValue:'',
        FWResponseTimerValue:'',
        FuncVW:'',
        SetV3Value:'',
        SetV4Value:'',
        SlopeOfApwrRedValue:'',
        VwResponseTimerValue:'',
        MinCapacityValue:'',
        ChargeMaxCurrentValue:'',
        DischargeMaxCurrentValue:'',
        NormalMidSocENCode:'',
        wMidSocValue:'',
        ExportLimitValue:'',
        GridConfigurationSelect:'',
        ReConnectionTime:'',
        MaxVoltValue:'',
        MinVoltValue:'',
        MaxFreqValue:'',
        MinFreqValue:'',
        NewPasswordValue:'',
        StartFreqValue:'',
        InvMaxPowValue:'',
        FreqDroopValue:'',
        FreqReverBatCapValue:''
      }
    }
  },
  methods: {
    onClickLeft(){
      this.$router.push({path:'/bdsetting'});
    },
    FuncLVConfirm(value,i){
      this.showFuncLV=false;
      this.LocalArr.FuncLV=value;
      this.FuncLVCode=i;
    },
    FuncHVConfirm(value,i){
      this.showFuncHV=false;
      this.LocalArr.FuncHV=value;
      this.FuncHVCode=i;
    },
    FuncLFConfirm(value,i){
      this.showFuncLF=false;
      this.LocalArr.FuncLF=value;
      this.FuncLFCode=i;
    },
    FuncHFConfirm(value,i){
      this.showFuncHF=false;
      this.LocalArr.FuncHF=value;
      this.FuncHFCode=i;
    },
    FuncRRConfirm(value,i){
      this.showFuncRR=false;
      this.LocalArr.FuncRR=value;
      this.FuncRRCode=i;
    },
    FuncPFConfirm(value,i){
      this.showFuncPF=false;
      this.LocalArr.FuncPF=value;
      this.FuncPFCode=i;
    },
    factModeConfirm(value,i){
      this.showPowerFact=false;
      this.LocalArr.factMode=value.text;
      this.factModeCode=value.code;
    },
    FuncFWConfirm(value,i){
      this.showFuncFW=false;
      this.LocalArr.FuncFW=value;
      this.FuncFWCode=i;
    },
    StartPointV1Confirm(value){
      this.showStartPointV1=false;
      this.LocalArr.startPointV1=value;
      if(this.LocalArr.startPointV1=='60.10'){
        this.LocalArr.startPointV2='59.96';
      }else{
        this.LocalArr.startPointV2='59.90';
      }
    },
    StartPointV2Confirm(value){
      this.showStartPointV2=false;
      this.LocalArr.startPointV2=value;
      if(this.LocalArr.startPointV2=='59.96'){
        this.LocalArr.startPointV1='60.10';
      }else{
        this.LocalArr.startPointV1='60.04';
      }
    },
    FuncVWConfirm(value,i){
      this.showFuncVW=false;
      this.LocalArr.FuncVW=value;
      this.FuncVWCode=i;
    },
    GridCsConfirm(value,i){
      this.showGridCs=false;
      this.LocalArr.GridConfigurationSelect=value;
      this.GridConfigurationSelectCode=Number(i)+1;
    },
    ReConnectConfirm(val){
      this.showReConnect=false;
      this.LocalArr.ReConnectionTime=val;
    },
    ReConnectConfirm2(val){
      this.showReConnect2=false;
      this.LocalArr.ReConnectionTime=val;
    },
    fiveChange(){
      let hour=this.LocalArr.ReConnectionTime.split(":");
      if(hour[0]==5){
        this.maxM=0;
      }else{
        this.maxM=59;
      }
    },
    tenChange(){
      let hour=this.LocalArr.ReConnectionTime.split(":");
      if(hour[0]==10){
        this.maxM2=0;
      }else{
        this.maxM2=59;
      }
    },
    P2validator(val){
      let vailed;
      if(val>=80&&val<=100){
        vailed=true;
      }else{
        vailed=false;
      }
      return vailed
    },
    async getData(){
      this.comm.loadingShow();
      let datas=await this.SETAPI.LocalIn({'optType':'ReadSetData','pwd':sessionStorage.getItem('bdPwd')});
      if(datas!=null||datas!=undefined){
        let dataArr = datas;
        this.safety=dataArr[4];
        sessionStorage.setItem('safety',this.safety);
        let gridnum1=dataArr[164];
        let remainder1=dataArr[164];
        let gridnum2=parseInt(gridnum1/2);
        let remainder2=gridnum2%2;
        let gridnum3=parseInt(gridnum2/2);
        let remainder3=gridnum3%2;
        let gridnum4=parseInt(gridnum3/2);
        let remainder4=gridnum4%2;
        let gridnum5=parseInt(gridnum4/2);
        let remainder5=gridnum5%2;
        let gridnum6=parseInt(gridnum5/2);
        let remainder6=gridnum6%2;
        let gridnum7=parseInt(gridnum6/2);
        let remainder7=gridnum7%2;
        let gridnum8=parseInt(gridnum7/2);
        let remainder8=gridnum8%2;
        let gridnum9=parseInt(gridnum8/2);
        let remainder9=gridnum9%2;
        let gridnum10=parseInt(gridnum9/2);
        let remainder10=gridnum10%2;
        this.FuncRRCode=remainder6;
        this.LocalArr.FuncRR=this.toggleArr[this.FuncRRCode];
        if(remainder7==0){
          this.FuncPFCode=0;
          this.LocalArr.FuncPF=this.GridSupportsArr[this.FuncPFCode];
          this.isSPF=false;
        }else if(remainder7==1){
          this.isSPF=true;
          this.FuncPFCode=2;
          this.LocalArr.FuncPF=this.GridSupportsArr[this.FuncPFCode];
        }
        if(remainder8==0){
          this.isQV=false;
        }else if(remainder8==1){
          this.isQV=true;
          this.FuncPFCode=1;
          this.LocalArr.FuncPF=this.GridSupportsArr[this.FuncPFCode];
        }
        this.FuncFWCode=remainder9;
        this.LocalArr.FuncFW=this.toggleArr[this.FuncFWCode];
        this.FuncVWCode=remainder10;
        this.LocalArr.FuncVW=this.toggleArr[this.FuncVWCode];
        this.FuncLVCode=remainder2;
        this.LocalArr.FuncLV=this.toggleArr[this.FuncLVCode];
        this.FuncHVCode=remainder3;
        this.LocalArr.FuncHV=this.toggleArr[this.FuncHVCode];
        this.FuncLFCode=remainder4;
        this.LocalArr.FuncLF=this.toggleArr[this.FuncLFCode];
        this.FuncHFCode=remainder5;
        this.LocalArr.FuncHF=this.toggleArr[this.FuncHFCode];
        this.LocalArr.VacMaxValue=dataArr[1];
        this.LocalArr.VacMaxSlowProtectValue=dataArr[8];
        this.LocalArr.TripTimeHV1Value=dataArr[74]/10;
        this.LocalArr.VacMinSlowProtectValue=dataArr[7];
        this.LocalArr.TripTimeLV1Value=dataArr[73]/10;
        this.LocalArr.LV2Value=dataArr[151];
        this.LocalArr.TripTimeLV2Value=dataArr[152]/10;
        this.LocalArr.VacMinValue=dataArr[0];
        this.LocalArr.TripTimeLV3Value=dataArr[69]/10;
        this.LocalArr.FacMaxValue=dataArr[3]/100;
        this.LocalArr.TripTimeHF2Value=(dataArr[72]*0.02).toFixed(2);
        this.LocalArr.FacMaxSlowProtectValue=dataArr[10]/100;
        this.LocalArr.TripTimeHF1Value=(dataArr[76]*0.02).toFixed(2);
        this.LocalArr.FacMinSlowProtectValue=dataArr[9]/100;
        this.LocalArr.TripTimeLF1Value=(dataArr[75]*0.02).toFixed(2);
        this.LocalArr.FacMinValue=dataArr[2]/100;
        this.LocalArr.TripTimeLF2Value=(dataArr[71]*0.02).toFixed(2);
        this.LocalArr.NormRampRateValue=dataArr[167]/100;
        this.LocalArr.SoftRampUpRateValue=dataArr[168]/100;
        this.factModeCode=dataArr[13];
        this.LocalArr.factMode=this.factorArr[this.factModeCode-1].text;
        this.LocalArr.P2Value=dataArr[14];
        this.LocalArr.Q1Value=this.comm.bit16(0,dataArr[105])/10;
        this.LocalArr.Q2Value=this.comm.bit16(0,dataArr[106])/10;
        this.LocalArr.Q3Value=this.comm.bit16(0,dataArr[107])/10;
        this.LocalArr.Q4Value=this.comm.bit16(0,dataArr[108])/10;
        this.LocalArr.VrefValue=dataArr[109]/10;
        this.LocalArr.ResponseTimeValue=dataArr[110]/10;
        this.LocalArr.V1Value=dataArr[111]/10;
        this.LocalArr.V2Value=dataArr[112]/10;
        this.LocalArr.V3Value=dataArr[113]/10;
        this.LocalArr.V4Value=this.comm.bit16(0,dataArr[114])/10;
        this.LocalArr.startPointV1=(dataArr[162]/100).toFixed(2);
        this.LocalArr.startPointV2=(dataArr[161]/100).toFixed(2);
        this.LocalArr.dbOFValue=dataArr[115]/1000;
        this.LocalArr.dbUFValue=dataArr[116]/1000;
        this.LocalArr.KOFValue=dataArr[117]/100;
        this.LocalArr.KUFValue=dataArr[118]/100;
        this.LocalArr.FWResponseTimerValue=dataArr[119]/10;
        this.LocalArr.SetV3Value=dataArr[127]/10;
        this.LocalArr.SetV4Value=dataArr[128]/10;
        this.LocalArr.SlopeOfApwrRedValue=dataArr[166]/10;
        this.LocalArr.VwResponseTimerValue=dataArr[120]/10;
        //铅酸电池判断
        if(dataArr[32]==0){
          this.isLeadAcid=false;
        }else{
          this.isLeadAcid=true;
        }
        this.LocalArr.MinCapacityValue=dataArr[31];
        this.LocalArr.ChargeMaxCurrentValue=dataArr[35]/100;
        this.LocalArr.DischargeMaxCurrentValue=dataArr[36]/100;
        this.LocalArr.LowSocChgFromGridValue=dataArr[189];
        this.LocalArr.BatAwakenValue=dataArr[95];
        this.LocalArr.NormalMidSocENCode=dataArr[190];
        this.LocalArr.wMidSocValue=dataArr[191];
        this.LocalArr.ExportLimitValue=dataArr[63];
        this.LocalArr.GlblMPPTFunctionCode=dataArr[142];
        this.GridConfigurationSelectCode=Number(dataArr[165])-1;
        this.LocalArr.GridConfigurationSelect=this.GridCsArr[this.GridConfigurationSelectCode];
        let ReConnectHour=parseInt(dataArr[169]/60)>9?parseInt(dataArr[169]/60):'0'+parseInt(dataArr[169]/60);
        let ReconnectMinute=parseInt(dataArr[169]%60)>9?parseInt(dataArr[169]%60):'0'+parseInt(dataArr[169]%60);
        this.LocalArr.ReConnectionTime=`${ReConnectHour}:${ReconnectMinute}`;
        if(ReConnectHour==5){
          this.maxM=0;
        }else{
          this.maxM=59;
        }
        if(ReConnectHour==10){
          this.maxM2=0;
        }else{
          this.maxM2=59;
        }
        this.LocalArr.MaxVoltValue=dataArr[121];
        this.LocalArr.MinVoltValue=dataArr[122];
        this.LocalArr.MaxFreqValue=dataArr[123]/10;
        this.LocalArr.MinFreqValue=dataArr[124]/10;
        this.LocalArr.NewPasswordValue=this.comm.showPwd(dataArr[104]);
        this.LocalArr.StartFreqValue=dataArr[170]/100;
        this.LocalArr.InvMaxPowValue=dataArr[171];
        this.LocalArr.FreqDroopValue=dataArr[172];
        this.LocalArr.FreqReverBatCapValue=dataArr[173];
      }else{
        this.comm.tipsShow('InvNoResponse');
      }
    },
    //设置安规
    setSafety(data){
      if(data=='success'){
        this.safety=sessionStorage.getItem('safety');
      }
    },
    //设置GridSupport
    async GridSupport(e){
      e.stopPropagation();
      //处理数据
      let Value=0;
      if(this.FuncPFCode==1){
        Value=this.FuncLVCode*2+this.FuncHVCode*4+this.FuncLFCode*8+this.FuncHFCode*16+this.FuncRRCode*32+128+this.FuncFWCode*256+this.FuncVWCode*512;
      }else if(this.FuncPFCode==2){
        Value=this.FuncLVCode*2+this.FuncHVCode*4+this.FuncLFCode*8+this.FuncHFCode*16+this.FuncRRCode*32+64+this.FuncFWCode*256+this.FuncVWCode*512;
      }else{
        Value=this.FuncLVCode*2+this.FuncHVCode*4+this.FuncLFCode*8+this.FuncHFCode*16+this.FuncRRCode*32+this.FuncFWCode*256+this.FuncVWCode*512;
      }
      var Datas={'num':1,'Data':[{'reg':153,'val':Value+''}]};
      let params={
        'optType':"setReg",
        'Data':JSON.stringify(Datas),
        'pwd':sessionStorage.getItem('bdPwd')
      };
      this.comm.loadingShow();
      let data = await this.SETAPI.LocalIn(params);
      let newdata = data.substring(0,1);
      if (newdata == "Y") {
        this.comm.toastSuccess();
        /*判断用户的选择*/
        if(this.FuncPFCode==0){
          this.isSPF=false;
          this.isQV=false;
        }else if(this.FuncPFCode==1){
          this.isSPF=false;
          this.isQV=true;
        }else if(this.FuncPFCode==2){
          this.isSPF=true;
          this.isQV=false;
        }
      } else {
        this.comm.toastFail();
      }
    },
    //设置powerfactor
    powerfactorSubmit(){
      this.comm.bdSetDataPT(1,[{'reg':24,'val':(this.LocalArr.P2Value*256+Number(this.factModeCode))+''}]);
    },
    //设置startPoint
    startPointSubmit(){
      let formData=[
        {'reg':149,'val':(this.comm.mulFunction(this.LocalArr.startPointV1,100))+''},
        {'reg':148,'val':(this.comm.mulFunction(this.LocalArr.startPointV2,100))+''}
      ];
      this.comm.bdSetDataPT(2,formData);
    },
    //设置Grid Configuration Select
    setGridCs(e){
      e.stopPropagation();
      let formData=[{'reg':154,'val':(Number(this.GridConfigurationSelectCode)+1)+''}];
      this.comm.bdSetDataPT(1,formData);
    },
    //设置ReConnection Set
    setReConnect(e){
      e.stopPropagation();
      let timeArr=this.LocalArr.ReConnectionTime.split(':');
      let formData=[{'reg':158,'val':(timeArr[0]*60+Number(timeArr[1]))+''}];
      this.comm.bdSetDataPT(1,formData);
    },
    onRefresh(){
      this.isLoading = false;
      this.timer=new Date().getTime();
      for(let i in this.LocalArr){
        this.LocalArr[i]='';
      }
      this.getData();
    }
  },
  mounted(){
    setTimeout(()=>{
      this.getData();
    },1000);
  }
}
</script>

<style scoped lang="less">

</style>
